#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "CountSensor.h"
#include "PID.h"
#include "dingshiqi.h"
#include "yuntai.h"
#include "shexiangtou.h"
int flag_task=0;
uint16_t count = 0;
uint8_t shexiangtou_zl[]={0x50,0x54,0x50}; //指令1
int main(void)
{
	/*模块初始化*/
	dingshiqi_Init();	//定时器初始化
	Yuntai_Init();
	CountSensor_Init(); 
	shexiangtou_Init();	//摄像头初始化
	shexiangtou_SendString(shexiangtou_zl);
	yuntai_SFLJ();	//云台初始化
	PID_Init(&yuntai_pid_x,1,0,0);
	PID_Init(&yuntai_pid_y,1,0,0);
	while (1)
	{
		if(flag_queding())flag_task=1; //复位
		if(flag_xia())flag_task=2; //屏幕巡线
		if(flag_fanhui())flag_task=3; //A4纸巡线
 		if(flag_jia())flag_task=4; //暂停
		if(count==5){
		switch (flag_task)
				{
				case 1:
					yuntai_fuwei();
					break;
				case 2:
					yuntai_xunxian();
					break;
				case 3:
					yuntai_xunxian();
					break;
				case 4:
					yuntai_STOP();
					break;
				default:
					break;
				}
		}
		
	}
}

void TIM4_IRQHandler(void){
    if(TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET){
		if(count == 5){
		
			count = 0;
		}
		count++;
		
        TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
    }
}
